package com.fafu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;

public class Update04 {
    public static void main(String[] args) throws Exception{
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入密码");
        String psw = scanner.next();

        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=UTF-8","root","root");
        String sql = "UPDATE `student` SET `loginpwd`=? WHERE `studentno`=1";
        PreparedStatement pstm = connection.prepareStatement(sql);
        pstm.setString(1,psw);
        int i = pstm.executeUpdate();
        if(i>=1){
            System.out.println("操作成功");
        }
        else {
            System.out.println("操作失败");
        }
        pstm.close();
        connection.close();
    }
}
